/**
 * Created by 111 on 2015/10/22.
 */
//删除
function deleteRole(id){
	$.ajax({
		type:'post',
		url:'/MSAPortal/Portalrole/removeRole.do',
		data:{'roleId':id},
		datatype:'text',
		success:function(data){
			alert(data);
			$("#center").load("/MSAPortal/Portalrole/roleManage.do");
		},
		error:function(){
			alert("错误");
		}
	});
}
//保存
function saveRole(){
	var nodes = ztree.getCheckedNodes(true);
	var nodesp = ztreep.getCheckedNodes(true);
	var perms="";
	var permps="";
	var permgs="";
	var permts="";
	for(var i=0;i<nodes.length;i++){
		if(nodes[i].permf!=null){
		    perms += nodes[i].permf+ ",";
		}
	}
	for(var j=0;j<nodesp.length;j++){
		if(nodesp[j].permp!=null){
			permps += nodesp[j].permp+",";
		}else if(nodesp[j].permg!=null){
			permgs += nodesp[j].permg+",";
		}else if(nodesp[j].permt!=null){
			permts += nodesp[j].permt+",";
		}
	}
	if(perms.length>0) {
		perms = perms.substring(0,perms.length-1);
	}
	if(permps.length>0) {
		permps = permps.substring(0,permps.length-1);
	}
	if(permgs.length>0) {
		permgs = permgs.substring(0,permgs.length-1);
	}
	if(permts.length>0) {
		permts = permts.substring(0,permts.length-1);
	}
	
	$("#permfs").val(perms);
	$("#permps").val(permps);
	$("#permgs").val(permgs);
	$("#permts").val(permts);
	var roleName =$.trim($('#title').val());
	var roleNo = $.trim($('#pagetit').val());
	var nameReg = /^[0-9]{2,50}$/;
	var rolenum = new RegExp("^[0-9]*$");	
	if(nameReg.test(roleName)||roleName == ''){
		alert("角色命名不符合要求！");
	}else if(!rolenum.test(roleNo)||roleNo==''){
		alert("排序只能是非零的数字！");
	}else{
		$.ajax({
			type:'post',
			url:'/MSAPortal/Portalrole/saveRole.do',
			data:$('#rolemore').serialize(),
			datatype:'text',
			success:function(data){
				alert(data);
				$("#center").load("/MSAPortal/Portalrole/roleManage.do");
			},
			error:function(){
				alert("保存失败");
			}
		});
	}

}

//查询
function findRole(){
	var roletitle = $('#findrolename').val();
	$("#center").load("/MSAPortal/Portalrole/roleManage.do",{role_name:roletitle});
}
function pageturn(pageNum){
	var roletitle = $('#findrolename').val();
	$("#center").load("/MSAPortal/Portalrole/roleManage.do",{role_name:roletitle,pageNo:pageNum});
}
